package com.ludomancy.gamelib;

import java.applet.AudioClip;
import java.util.Iterator;
import java.util.Vector;

public class Sound
{
	AudioClip clip;
	public static boolean soundActivated = true;
	private static Vector sounds = new Vector();
	
	public Sound(String path)
	{
		clip = ResourceManager.getSound(path);
		if(clip == null)
		{
			throw new RuntimeException("Missing file: "+path);
		}
	}
	
	public static void pauseAll()
	{
		for (Iterator iterator = sounds.iterator(); iterator.hasNext();)
		{
			Sound s = (Sound) iterator.next();
			s.stop();
		}
	}
		
	public static void play(String path)
	{
		if(soundActivated)
		{
			new Sound(path).play();
		}
	}
	
	public void loop()
	{
		if(soundActivated)
		{
			clip.loop();
		}
	}
	
	public void play()
	{
		if(soundActivated)
		{
			clip.play();
		}
	}
	
	public void stop()
	{
		clip.stop();
	}
}
